<template>
  <el-container>
    <el-aside width="200px">
      <SideMenu></SideMenu>
    </el-aside>
    <el-container>
      <el-header style="height: 55px;">
        <Strong>与 时 网 后 台 管 理 系 统</Strong>
        <div class="header-avatar block">
          <el-avatar class="el-avatar" size="medium" :src="adminInfo.avatar"></el-avatar>
          <el-dropdown>
                        <span class="el-dropdown-link">
                          {{adminInfo.username}}<i class="el-icon-arrow-down el-icon--right"></i>
                        </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item :underline="false">
                <router-link to="/sys/admin">个人中心</router-link>
              </el-dropdown-item>
              <el-dropdown-item @click.native="logout">退出</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </el-header>
      <el-main>

        <div style="margin: 0 15px;">
          <router-view></router-view>
        </div>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import SideMenu from './SideMenu.vue'


export default {
  name: 'Home',
  components: {
    SideMenu
  },
  data() {
    return {
      adminInfo: {
        id: " ",
        username: " ",
        avatar: " "
      }
    }
  },
  created() {
	if(this.$store.getters.getAdmin.username) {
	  this.adminInfo.username = this.$store.getters.getAdmin.username
	  this.adminInfo.avatar = this.$store.getters.getAdmin.avatar
	}
  },
  methods: {
    logout() {
      this.$axios.post("/logout",{
		      headers: {
		        "Authorization": localStorage.getItem("token")
		      }
			},).then(res => {
				this.$store.commit("REMOVE_ADMIN")
				this.$router.push("/admin")
				this.$message({
			    message: '已退出登录',
			    type: 'error'
			  });
      })
    }
	
  }
}
</script>

<style>
.el-container {
  padding: 0;
  margin: 0;
  height: 100%;
}

.header-avatar {
  float: right;
  width: 150px;
  display: flex;
  justify-content: space-around;
  align-items: center;
}

.el-dropdown-link {
  cursor: pointer;
}

.el-header {
  background-color: #409EFF;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: #D3DCE6;
  color: #333;
  line-height: 200px;
}

.el-main {
  color: #333;
  padding: 0;
}

a {
  text-decoration: none;
}
</style>
